﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PSIMIS2019.SubPages
{
    public partial class _ChooseProducts : Form
    {
        List<Product> pList;
        Product p = new Product();
        ProductBLL bl;
        public _ChooseProducts()
        {
            InitializeComponent();
            bl = new ProductBLL();
            pList = new List<Product>();
            BindData();
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Close();//关闭当前窗体
        }
        private  void BindData()
        {
            pList = bl.GetList();
            dgvProducts.DataSource = pList;
            if (dgvProducts.CurrentCell != null)
            {
                dgvProducts.CurrentCell.Selected = false;
            }
        }

        private void dgvProducts_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //单行选择
            dgvProducts.CurrentRow.Selected = true;
            p = pList[e.RowIndex];
        }

        private void dgvProducts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            //完成产品类型的名称列表显示
            if (dgvProducts.Columns[e.ColumnIndex].Name == "CategoryID")
                e.Value = new CategoryBLL().FindByID(e.Value.ToString()).CategoryName;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            PurchaseDetail detail = new PurchaseDetail();
            detail.ProductID = p.ProductID;
            detail.Quantity = p.Quantity;
            detail.PurchasePrice = p.PurchasePrice;
            _PurchaseBill.addDetail = detail;

            this.Close();//关闭当前窗口
        }
    }
}
